﻿using System.Windows.Input;
using TallyJ.Announcer;
using TallyJ.FrontDesk;

namespace TallyJ.Windows
{
  /// <summary>
  /// Interaction logic for Launch.xaml
  /// </summary>
  public partial class Launch
  {
    ///<summary></summary>
    public static RoutedCommand LaunchAnnouncerCommand = new RoutedCommand();

    ///<summary></summary>
    public static RoutedCommand LaunchDbToolsCommand = new RoutedCommand();

    ///<summary></summary>
    public static RoutedCommand LaunchFrontDeskCommand = new RoutedCommand();


    public Launch()
    {
      InitializeComponent();

      CommandBindings.Add(new CommandBinding(LaunchDbToolsCommand, LaunchDbTools, CanLaunchDbTools));
      CommandBindings.Add(new CommandBinding(LaunchAnnouncerCommand, LaunchAnnouncer, CanLaunchAnnouncer));
      CommandBindings.Add(new CommandBinding(LaunchFrontDeskCommand, LaunchFrontDesk, CanLaunchFrontDesk));

      btnLaunchDbTools.Command = LaunchDbToolsCommand;
      btnLaunchAnnouncer.Command = LaunchAnnouncerCommand;
      btnLaunchFrontDesk.Command = LaunchFrontDeskCommand;

      btnLaunchFrontDesk.Focus();

      KeyDown += OnKeyDown;
    }

    private void OnKeyDown(object sender, KeyEventArgs args)
    {
      switch (args.Key)
      {
        case Key.Escape:
          Close();
          break;
        case Key.A:
          LaunchAnnouncer(this, null);
          break;
        case Key.D:
          LaunchDbTools(this, null);
          break;
        case Key.F:
          LaunchFrontDesk(this, null);
          break;
      }
    }

    private void CanLaunchAnnouncer(object sender, CanExecuteRoutedEventArgs e)
    {
      e.CanExecute = true;
    }

    private void LaunchAnnouncer(object sender, ExecutedRoutedEventArgs e)
    {
      var x = new AnnouncerPresenter();
      x.ShowDialog();
    }

    private void CanLaunchFrontDesk(object sender, CanExecuteRoutedEventArgs e)
    {
      e.CanExecute = true;
    }

    private void LaunchFrontDesk(object sender, ExecutedRoutedEventArgs e)
    {
      var x = new FrontDeskPresenter();
      x.ShowDialog();
    }

    private void LaunchDbTools(object sender, ExecutedRoutedEventArgs e)
    {
      var w = new DbTools {Owner = this};
      w.ShowDialog();
    }

    private void CanLaunchDbTools(object sender, CanExecuteRoutedEventArgs e)
    {
      e.CanExecute = true;
    }
  }
}